package com.mai4j.maiadmin.configure;

import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;
import java.util.ArrayList;
import java.util.List;

/**
 * 微信公众号请关注: 开源螺丝钉
 * <br>
 * 码云请关注: <a href="https://gitee.com/xiyoufang">https://gitee.com/xiyoufang</a>
 * <br>
 * 哔哩哔哩请关注: <a href="https://space.bilibili.com/438927834">https://space.bilibili.com/438927834</a>
 *
 * @author xiyoufang
 */
@Configuration
@ConfigurationProperties(prefix = "mai")
@Setter
@Getter
public class MaiProperties {

    @Setter
    @Getter
    public static class Id {
        /**
         * 节点ID
         */
        private long workerId;
    }

    @Setter
    @Getter
    public static class I18n {
        /**
         * 资源路径
         */
        private String path;
        /**
         * 文件系统资源名称
         */
        private List<String> fileBundles = new ArrayList<>();
        /**
         * classpath
         */
        private List<String> classpathBundles = new ArrayList<>();
        /**
         * 文件编码
         */
        private String encoding = "UTF-8";
        /**
         * 缓存时间
         */
        private Duration cacheDuration = Duration.ofMillis(-1);
    }

    /**
     * 缓存名称配置
     */
    @Setter
    @Getter
    public static class Cache {

        @Setter
        @Getter
        @Accessors(chain = true)
        public static class Item {
            /**
             * 名称
             */
            private String name;
            /**
             * 超时时间 ehcache3 该配置不生效
             */
            private Duration ttl;
        }

        /**
         * Session缓存
         */
        private Item session = new Item().setName("session").setTtl(Duration.ofHours(1));
        /**
         * 数据缓存
         */
        private Item data = new Item().setName("data").setTtl(Duration.ofDays(1));
        /**
         * Flash
         */
        private Item flash = new Item().setName("flash").setTtl(Duration.ofMinutes(10));
    }

    @Setter
    @Getter
    public static class Template {
        /**
         * 路径
         */
        private String basePath;
        /**
         * 模板是否热更新
         */
        private boolean hot;
    }

    /**
     * 网关URL
     */
    private String gateway = "/";
    /**
     * jwt密钥
     */
    private String jwtKey;
    /**
     * JS和CSS等静态资源的路径
     */
    private String resourcePath;
    /**
     * 图片路径
     */
    private String imagePath;
    /**
     * 模板配置
     */
    private Template template;
    /**
     * ID 配置
     */
    private Id id = new Id();
    /**
     * i18n配置
     */
    private I18n i18n = new I18n();
    /**
     * 缓存名称
     */
    private Cache cache = new Cache();

}
